package com.yequan.leetcode.string.isPalindrome_125;

/**
 * @author yequan
 * @date 2022/02/23 07:50
 **/
public class IsPalindrome {

    public boolean isPalindrome(String s) {
        if (s == null || s == "") {
            return false;
        }
        int left = 0, right = s.length() - 1;
        while (left < right) {
            while (left < right && !Character.isLetterOrDigit(s.charAt(left))) {
                left++;
            }
            while (left < right && !Character.isLetterOrDigit(s.charAt(right))) {
                right--;
            }
            if (left < right) {
                if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) {
                    return false;
                }
                left++;
                right--;
            }
        }
        return true;
    }

}
